package com.example.fuzhuang.controller;

import com.example.fuzhuang.dto.Product;
import com.example.fuzhuang.req.ProductReq;
import com.example.fuzhuang.resp.CommonResp;
import com.example.fuzhuang.resp.PageResp;
import com.example.fuzhuang.resp.ProductResp;
import com.example.fuzhuang.resp.SumInventoryResp;
import com.example.fuzhuang.services.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController //这是返回接口
@RequestMapping("/product")
public class ProductController {

    private static final Logger LOG = LoggerFactory.getLogger(ProductController.class);

    @Resource
    private ProductService productService;

    @GetMapping("/list")
    public CommonResp<PageResp<ProductResp>> list(@Valid ProductReq req){
        CommonResp<PageResp<ProductResp>> resp= new CommonResp<>();
        PageResp<ProductResp> productRespList = productService.list(req);
        resp.setData(productRespList);
        return  resp;
    }

    @GetMapping("/myList")
    public CommonResp<PageResp<ProductResp>> myList(@Valid ProductReq req){
        CommonResp<PageResp<ProductResp>> resp= new CommonResp<>();
        PageResp<ProductResp> productRespList = productService.myList(req);
        resp.setData(productRespList);
        return  resp;
    }

    @PostMapping("/getProduct")
    public CommonResp<List<ProductResp>> getProduct(@Valid @RequestBody ProductReq req){
        CommonResp<List<ProductResp>> resp= new CommonResp<>();
        List<ProductResp> productRespList = productService.getProduct(req);
        resp.setData(productRespList);
        return  resp;
    }

    @PostMapping("/inventoryInput")
    public CommonResp<ProductResp> inventoryInput(@Valid @RequestBody ProductReq req){
        CommonResp<ProductResp> resp= new CommonResp<>();
        ProductResp productResp = productService.inventoryInput(req);
        resp.setData(productResp);
        return  resp;
    }

    @PostMapping("/inventoryOutput")
    public CommonResp<ProductResp> inventoryOutput(@Valid @RequestBody ProductReq req){
        CommonResp<ProductResp> resp= new CommonResp<>();
        ProductResp productResp = productService.inventoryOutput(req);
        resp.setData(productResp);
        return  resp;
    }

    @PostMapping("/save")
    public CommonResp<Product> save(@Valid @RequestBody ProductReq req){
        CommonResp<Product> resp= new CommonResp<>();
        Product product = productService.save(req);
        resp.setData(product);
        return resp;
    }

    @GetMapping("/delete")
    public CommonResp delete(@Valid ProductReq req){
        CommonResp resp= new CommonResp<>();
        productService.delete(req);
        return  resp;
    }

    @GetMapping("/getSumInventory")
    public CommonResp<List<SumInventoryResp>> getSumInventory(@Valid ProductReq req){
        CommonResp<List<SumInventoryResp>> resp= new CommonResp<>();
        List<SumInventoryResp> listSumInventoryResp = productService.getSumInventory(req);
        resp.setData(listSumInventoryResp);
        return  resp;
    }

}

